﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Products.ascx.cs" Inherits="controls_admin_Products" %>
<!-- table -->
<script src="../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="../Scripts/jquery.tablednd_0_5.js" type="text/javascript"></script>
<script type="text/javascript">
    var variable = "0";
    var mid = <%= mid%>;
    var j = jQuery.noConflict();
    var index = "";
    function getCheck() {
        j("table input[type=checkbox].item").each(function () {
            var checked = j(this).attr("checked");
            if (checked) {
                index = index + j(this).attr("value") + ";";
            }
        });
        j("#<%=hdfCheck.ClientID%>").val(index);
    }
    j(document).ready(function () {
        if(mid > 0 ){
            j('#table-3').tableDnD({
                onDrop: function (table, row) {
                    variable = j.tableDnD.serialize();
                }
            });
            j("#update").style.display = 'block';
            $("#<%=ddlCategory.ClientID %>").style.display = 'none';
        }
        else{
            j('#table-3 tr').css({'cursor' : 'default'});
        }
        j("#<%=btnDel.ClientID%>").click(function () {
            getCheck();
            if (index == "") return false;
            else return confirm("Xác nhận xóa !");
        }); 
        j("#update").click(function () {
            if (variable == "0")
                return false;
            j.ajax({
                type: "POST",
                url: "../services/WebService.asmx/productorder",
                data: "{'id':'&" + variable + "','mid':'"+ mid +"'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                beforeSend: function () {
                    j("#<%=divMessage.ClientID %>").html("");
                },
                success: function (message) {
                    if (message.d == false) {
                        // Ẩn Nút Submit nếu UserName không hợp lệ
                        //alert("error");
                        j("#<%=divMessage.ClientID %>").html("<div id='message-error' class='message message-error'><div class='image'><img src='../resources/images/icons/error.png' alt='Error' height='32' /></div><div class='text'><h6>Lỗi</h6><span>Chưa thực hiện được!</span></div><div class='dismiss'><a href='#message-error'></a></div></div>");
                    }
                    else {
                        //alert("ok");
                        j("#<%=divMessage.ClientID %>").html("<div id='message-success' class='message message-success'><div class='image'><img src='../resources/images/icons/success.png' alt='Success' height='32' /></div><div class='text'><h6>Thông Báo</h6><span>Cập nhật thành công !</span></div><div class='dismiss'><a href='#message-success'></a></div></div>");
                    }
                },
                error: function (errormessage) {
                    //Hiển thị lỗi nếu xảy ra
                    //alert(errormessage);
                    j("#<%=divMessage.ClientID %>").html("<div id='message-error' class='message message-error'><div class='image'><img src='../resources/images/icons/error.png' alt='Error' height='32' /></div><div class='text'><h6>Lỗi</h6><span>Chưa thực hiện được!</span></div><div class='dismiss'><a href='#message-error'></a></div></div>");
                }
            });            
        });
        j("#new").click(function(){
            window.location.replace( window.location.pathname + "?module=productsadd" );
        });
    });
</script>
<asp:HiddenField ID="hdfCheck" runat="server" />
<div class="box">
    <!-- box / title -->
    <div class="title">
        <h5 id="title" runat="server">
            Danh Sản Phẩm</h5>
        <div class="search">
            <div class="input">
                <input id="txtSearch" runat="server" style="width: 200px" value="Hãy nhập từ khóa !"
                    onclick='if(this.value=="Hãy nhập từ khóa !")this.value=""' onblur='if(this.value=="")this.value="Hãy nhập từ khóa !"' />
            </div>
            <div class="button">
                <asp:Button ID="btnSearch" runat="server" Text="Tìm kiếm" OnClick="btnSearch_Click" />
            </div>
        </div>
    </div>
    <div id="divMessage" runat="server">
    </div>
    <div id="divResult" runat="server" class="result">
    </div>
    <div class="first-action">
        <asp:DropDownList AutoPostBack="true" ID="ddlCategory" runat="server" OnSelectedIndexChanged="ddlCategory_SelectedIndexChanged"
            CssClass="select" />
    </div>
    <!-- end box / title -->
    <div class="table">
        <table id="table-3">
            <thead>
                <tr>
                    <th>
                        STT
                    </th>
                    <th>
                        Ảnh mô tả
                    </th>
                    <th>
                        Tên sản phẩm
                    </th>
                    <th>
                        Mã sản phẩm
                    </th>
                    <th>
                        Giá
                    </th>
                    <th>
                        Ngày đăng
                    </th>
                    <th>
                        Sửa
                    </th>
                    <th class="selected last">
                        <input type="checkbox" class="checkall" />
                    </th>
                </tr>
            </thead>
            <tbody>
                <asp:Repeater ID="rptData" runat="server">
                    <ItemTemplate>
                        <tr id="<%#Eval("PRODUCT_ID") %>" style="cursor: move">
                            <td align="center">
                                <%#(Container.ItemIndex+1)+(base.Cur_page-1)*base.Page_size %>
                            </td>
                            <td>
                                <img src='../upload/products/<%#Eval("THUMB_IMAGE")%>' title='<%#Eval("PRODUCT_NAME")%>'
                                    alt='<%#Eval("PRODUCT_NAME")%>' height="100" onerror="ImgError(this);" />
                            </td>
                            <td align="center">
                                <%#Eval("PRODUCT_NAME")%>
                            </td>
                            <td align="center">
                                <%#Eval("PRODUCT_CODE")%>
                            </td>
                            <td align="center">
                                <%#Eval("UNIT_PRICE")%>
                            </td>
                            <td align="center">
                                <%#LibraryO2S.O2S_DateTime.dd_MM_yyyy(Convert.ToDateTime(Eval("CREATED_DATE")))%>
                            </td>
                            <td align="center">
                                <a href='<%#"default.aspx?module=productsedit&pid="+Eval("PRODUCT_ID")%>' title="Chỉnh Sửa">
                                    <img src="../Resources/icons/16x16/edit.png" class="icon-32-edit" alt="chỉnh sửa" />
                                </a>
                            </td>
                            <td align="center" class="last">
                                <input type="checkbox" value='<%#Eval("PRODUCT_ID")%>' class="item" />
                            </td>
                        </tr>
                    </ItemTemplate>
                </asp:Repeater>
            </tbody>
        </table>
        <div class="pagination pagination-left last">
            <div class="pagerContainer" id="pagerContainer" runat="server">
            </div>
        </div>
        <div class="action">
            <div class="button">
                <input id="new" type="button" value="Thêm Mới" />
                <input type="button" value="Cập nhật thứ tự" id="update" style="display: none" />
                <asp:Button ID="btnDel" runat="server" Text="Xóa" OnClick="btnDel_Click" />
            </div>
        </div>
    </div>
</div>
<!-- end table -->
